package com.gitee.lw114514.webapp_spring_1.dao.impl;

import cn.hutool.core.io.IoUtil;
import com.gitee.lw114514.webapp_spring_1.dao.UserDao;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

//@Component
@Repository // 将类交给spring管理
public class UserDaoImpl implements UserDao {
    @Override
    public List<String> findAll(){
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("user_information.txt");
        // 添加空值检查
        if (inputStream == null) {
            System.err.println("user_information.txt文件未找到");// 返回空列表而不是抛出异常
            return new ArrayList<>();
        }
        ArrayList<String> lines = IoUtil.readLines(inputStream, StandardCharsets.UTF_8, new ArrayList<>());
        return lines;

    }
}
